package com.weetop.aklyscan.activity;

import android.content.Intent;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import android.util.Base64;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.ToastUtils;
import com.classic.adapter.BaseAdapterHelper;
import com.classic.adapter.CommonRecyclerAdapter;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.interfaces.OnSelectListener;
import com.weetop.aklyscan.R;
import com.weetop.aklyscan.appConfig.GlideImageLoader;
import com.weetop.aklyscan.appConfig.MyApplication;
import com.weetop.aklyscan.base.BaseFragment;
import com.weetop.aklyscan.base.BaseUrl;
import com.weetop.aklyscan.base.mvp.BaseModel;
import com.weetop.aklyscan.bean.ChaXunDetailBean;
import com.weetop.aklyscan.bean.ChaXunDetailBean1;
import com.weetop.aklyscan.bean.ChaXunDetailBean2;
import com.weetop.aklyscan.bean.OrderDetailBean;
import com.weetop.aklyscan.bean.SendRecordBean;
import com.weetop.aklyscan.presenter.SendOutPresent;
import com.weetop.aklyscan.utils.widget.MyDialogUtil;
import com.weetop.aklyscan.view.SendOutView;

import org.angmarch.views.NiceSpinner;
import org.angmarch.views.OnSpinnerItemSelectedListener;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import ZPL.ZPLPrinterHelper;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import cc.shinichi.library.tool.utility.ui.ToastUtil;

public class Fragment_query extends BaseFragment<SendOutPresent> implements SendOutView {
    private static final int HUOJIA_CODE = 12000;
    private static final int REQUEST_HUOJIA_CODE_SCAN_ONE = 22000;
    Unbinder unbinder;

    @BindView(R.id.search_type)
    TextView search_type;
    @BindView(R.id.orderid)
    TextView orderid;
    @BindView(R.id.send_out_type)
    TextView send_out_type;
    @BindView(R.id.userInfo)
    TextView userInfo;
    @BindView(R.id.content)
    TextView content;
    @BindView(R.id.num)
    TextView num;
    @BindView(R.id.chanpin_zl)
    TextView chanpin_zl;
    @BindView(R.id.sjzl)
    TextView sjzl;
    @BindView(R.id.order_type)
    TextView order_type;
    @BindView(R.id.mail_name)
    TextView mail_name;
    @BindView(R.id.chicun)
    TextView chicun;
    @BindView(R.id.mail_code)
    TextView mail_code;
    @BindView(R.id.code_num)
    TextView code_num;
    @BindView(R.id.mail_name1)
    TextView mail_name1;
    @BindView(R.id.spinner1)
    NiceSpinner spinner1;
    @BindView(R.id.spinner2)
    NiceSpinner spinner2;
    @BindView(R.id.order_type1)
    TextView order_type1;
    @BindView(R.id.tv_search_type)
    TextView tv_search_type;
    @BindView(R.id.mail_code1)
    TextView mail_code1;
    @BindView(R.id.code_num1)
    TextView code_num1;
    @BindView(R.id.btn_save)
    TextView btn_save;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.mail_ll1)
    LinearLayout mail_ll1;
    @BindView(R.id.mail_ll2)
    LinearLayout mail_ll2;
    @BindView(R.id.dayin_img)
    ImageView dayin_img;
    private CommonRecyclerAdapter<ChaXunDetailBean> adapter;
    private List<ChaXunDetailBean> list = new ArrayList<>();
    private List<SendRecordBean> recordBeans;
    private OrderDetailBean dateBean;
    private ChaXunDetailBean1 chaXunDetailBean1;
    private ChaXunDetailBean2 chaXunDetailBean2;

    private String orderCode, orderID, name, mobile, address, newOrderType;
    private boolean isBing, dyjStatus;
    private String[] mail_list;
    private String[] mail_list1;
    private int page1 = 0, page2 = 0;

    Handler handler1 = new Handler() {
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            if (msg.what == 1) {
                getDayinStatus();
                handler1.sendEmptyMessageDelayed(1, 1000);
            }
        }
    };

    @Override
    protected SendOutPresent createPresenter() {
        return new SendOutPresent(this, getActivity());
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = View.inflate(getActivity(), R.layout.fragment_query, null);
        unbinder = ButterKnife.bind(this, view);
        recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
        adapter = new CommonRecyclerAdapter<ChaXunDetailBean>(mActivity, R.layout.item_send_out, list) {
            @Override
            public void onUpdate(BaseAdapterHelper helper, ChaXunDetailBean item, int position) {
                helper.setText(R.id.tv_id, position + 1 + "");
                helper.setText(R.id.sn, item.getSn());
                helper.setText(R.id.name, item.getName());
                helper.setText(R.id.model, item.getModel());
                helper.setText(R.id.time, item.getTime());
                if ("2".equals(newOrderType)) {
                    helper.setImageResource(R.id.select, R.color.transparent);
                } else {
                    helper.setImageResource(R.id.select, R.mipmap.select_true);
                }
            }
        };
        recyclerView.setAdapter(adapter);
        search_type.setTag(0);

        return view;
    }

    @Override
    public void getInto38Success(BaseModel<String> o) {
        orderid.setText(orderCode);
        orderid.setBackgroundResource(R.drawable.et_grey);
        mPresenter.Into39(orderCode, "1");
    }

    @Override
    public void getInto39Success(BaseModel<OrderDetailBean> o) {
//        playRing("shujuyouxiao.mp3");
//        dateBean = o.getData();
//        list.clear();
//        list.addAll(dateBean.getItems_one());
//        adapter.clear();
//        adapter.addAll(list);
//        if (dateBean.getBh_status().equals("1")) {
//            send_out_type.setText("补发");
//            code_num.setText("2");
//            code_num1.setText("1");
//        } else {
//            if (dateBean.getMerger_status().equals("0")) {
//                send_out_type.setText("首发");
//                code_num.setText("1");
//                code_num1.setText("1");
//            } else {
//                send_out_type.setText("并发");
//                code_num.setText("1");
//                code_num1.setText("2");
//            }
//        }
//        userInfo.setText(dateBean.getExpress_user_name() + " " + dateBean.getExpress_user_tel() + "\n" +
//                dateBean.getExpress_address());
//        content.setText(dateBean.getOrder_details());
//        num.setText(list.size() + "");
//        chanpin_zl.setText(dateBean.getTotal_weight() + "kg");
//        sjzl.setText(TextUtils.isEmpty(dateBean.getActual_weight()) ? "" : dateBean.getActual_weight() + "kg");
//        name = dateBean.getExpress_user_name();
//        mobile = dateBean.getExpress_user_tel();
//        address = dateBean.getExpress_address();
//
//        if (dateBean.getPartner_type().equals("1")) {
//            order_type.setText("系统生成");
//        } else {
//            order_type.setText("手动输入");
//        }
//        mail_name.setText(dateBean.getExpress_name());
//        mail_code.setText(dateBean.getExpress_sn());
//        mail_code1.setText(dateBean.getOrder_sn());
//        chicun.setText(dateBean.getCube());
//        if (TextUtils.isEmpty(dateBean.getMerger_order_sn())) {
//            mail_list = new String[1];
//            mail_list[0] = dateBean.getExpress_sn();
//        } else {
//            mail_list = new String[2];
//            mail_list[0] = dateBean.getExpress_sn();
//            mail_list[1] = dateBean.getMerger_order_sn();
//        }
//        if (TextUtils.isEmpty(dateBean.getMerger_order_sn())) {
//            mail_list1 = new String[1];
//            mail_list1[0] = dateBean.getExpress_sn();
//        } else {
//            mail_list1 = new String[2];
//            mail_list1[0] = dateBean.getExpress_sn();
//            mail_list1[1] = dateBean.getMerger_order_sn();
//        }
    }

    @Override
    public void getInto41Success(BaseModel<ChaXunDetailBean1> o) {
        playRing("shujuyouxiao.mp3");
        orderid.setText(orderCode);
        mPresenter.Into43(orderCode);
        orderid.setBackgroundResource(R.drawable.et_grey);
        chaXunDetailBean1 = o.getData();

        boolean isBf = false;
        boolean isBuFa = false;
        if (chaXunDetailBean1.getBh_status().equals("1")) {
            send_out_type.setText("补发");
            isBuFa = true;
            code_num.setText("2");
        } else {
            if (chaXunDetailBean1.getMerger_status().equals("0")) {
                send_out_type.setText("首发");
                code_num.setText("1");
            } else {
                send_out_type.setText("并发");
                code_num.setText("1");
                isBf = true;
            }
        }

        newOrderType = chaXunDetailBean1.getNew_order_type();
        if ("2".equals(chaXunDetailBean1.getNew_order_type())) {
            send_out_type.setText("刷单");
            code_num.setText("1");
        }
        list.clear();
        for (int i = 0; i < chaXunDetailBean1.getItems_one().size(); i++) {
            ChaXunDetailBean bean = new ChaXunDetailBean();
            bean.setSn(chaXunDetailBean1.getItems_one().get(i).getSerial_code());
            bean.setName(chaXunDetailBean1.getItems_one().get(i).getGoods_name());
            bean.setModel(chaXunDetailBean1.getItems_one().get(i).getGoods_model());
            bean.setTime(chaXunDetailBean1.getItems_one().get(i).getCk_time());
            list.add(bean);
        }
        if (isBuFa) {
            if (chaXunDetailBean1.getItems_two() != null)
                for (int i = 0; i < chaXunDetailBean1.getItems_two().size(); i++) {
                    ChaXunDetailBean bean = new ChaXunDetailBean();
                    bean.setSn(chaXunDetailBean1.getItems_two().get(i).getSerial_code());
                    bean.setName(chaXunDetailBean1.getItems_two().get(i).getGoods_name());
                    bean.setModel(chaXunDetailBean1.getItems_two().get(i).getGoods_model());
                    bean.setTime(chaXunDetailBean1.getItems_two().get(i).getCk_time());
                    list.add(bean);
                }
        }
        if (isBf) {
            if (chaXunDetailBean1.getOrder_two_items_one() != null)
                for (int i = 0; i < chaXunDetailBean1.getOrder_two_items_one().size(); i++) {
                    ChaXunDetailBean bean = new ChaXunDetailBean();
                    bean.setSn(chaXunDetailBean1.getOrder_two_items_one().get(i).getSerial_code());
                    bean.setName(chaXunDetailBean1.getOrder_two_items_one().get(i).getGoods_name());
                    bean.setModel(chaXunDetailBean1.getOrder_two_items_one().get(i).getGoods_model());
                    bean.setTime(chaXunDetailBean1.getOrder_two_items_one().get(i).getCk_time());
                    list.add(bean);
                }
        }
        adapter.clear();
        adapter.addAll(list);
        if (isBf) {
            userInfo.setText(chaXunDetailBean1.getHb_shr_info());
        } else {
            userInfo.setText(chaXunDetailBean1.getExpress_user_name() + " " + chaXunDetailBean1.getExpress_user_tel() + "\n" +
                    chaXunDetailBean1.getExpress_address());
        }

        if (isBf) {
            content.setText(chaXunDetailBean1.getHb_order_details());
        } else {
            content.setText(chaXunDetailBean1.getOrder_details());
        }
        if (chaXunDetailBean1.getBh_status().equals("1")) {
            if (chaXunDetailBean1.getExpress_one() != null) {
                if (!TextUtils.isEmpty(chaXunDetailBean1.getExpress_one().getActual_weight())) {
                    sjzl.setText(chaXunDetailBean1.getExpress_one().getActual_weight().replace("g", "") + "g");
                }else{
                    if (!TextUtils.isEmpty(chaXunDetailBean1.getActual_weight()))
                        sjzl.setText(chaXunDetailBean1.getActual_weight().replace("g", "") + "g");
                }
            } else {
                if (!TextUtils.isEmpty(chaXunDetailBean1.getActual_weight()))
                    sjzl.setText(chaXunDetailBean1.getActual_weight().replace("g", "") + "g");
            }
        } else {
            if (!TextUtils.isEmpty(chaXunDetailBean1.getActual_weight()))
                sjzl.setText(chaXunDetailBean1.getActual_weight().replace("g", "") + "g");
        }

        name = chaXunDetailBean1.getExpress_user_name();
        mobile = chaXunDetailBean1.getExpress_user_tel();
        address = chaXunDetailBean1.getExpress_address();

        if (chaXunDetailBean1.getPartner_type().equals("1")) {
            order_type.setText("系统生成");
            dayin_img.setVisibility(View.VISIBLE);
            if (chaXunDetailBean1.getExpress_one() != null) {
                mail_name.setText(chaXunDetailBean1.getExpress_one().getExp_type());
                mail_code.setText(chaXunDetailBean1.getExpress_one().getKuaidinum());
            }

            if (chaXunDetailBean1.getBh_status().equals("1")) {
                if (chaXunDetailBean1.getExpress_one() != null) {
                    if(!TextUtils.isEmpty(chaXunDetailBean1.getExpress_one().getCube())) {
                        chicun.setText(chaXunDetailBean1.getExpress_one().getCube());
                    }else{
                        if (!TextUtils.isEmpty(chaXunDetailBean1.getCube()))
                            chicun.setText(chaXunDetailBean1.getCube());
                    }
                }else{
                    if (!TextUtils.isEmpty(chaXunDetailBean1.getCube()))
                        chicun.setText(chaXunDetailBean1.getCube());
                }
                if (!TextUtils.isEmpty(chaXunDetailBean1.getTotal_weight()))
                    chanpin_zl.setText(chaXunDetailBean1.getTotal_weight().replace("g", "") + "g");
            } else {
                chicun.setText(chaXunDetailBean1.getCube());
                if (isBf) {
                    chanpin_zl.setText(chaXunDetailBean1.getCount_shop_weight().replace("g", "") + "g");
                } else {
                    if (!TextUtils.isEmpty(chaXunDetailBean1.getTotal_weight()))
                        chanpin_zl.setText(chaXunDetailBean1.getTotal_weight().replace("g", "") + "g");
                }
            }
        } else {
            order_type.setText("手动输入");
            dayin_img.setVisibility(View.GONE);
            mail_name.setText(chaXunDetailBean1.getExpress_name());
            mail_code.setText(chaXunDetailBean1.getExpress_sn());
            chicun.setText(chaXunDetailBean1.getCube());
            if (isBf) {
                chanpin_zl.setText(chaXunDetailBean1.getCount_shop_weight().replace("g", "") + "g");
            } else {
                if (!TextUtils.isEmpty(chaXunDetailBean1.getTotal_weight()))
                    chanpin_zl.setText(chaXunDetailBean1.getTotal_weight().replace("g", "") + "g");
            }
        }
        if ("2".equals(chaXunDetailBean1.getNew_order_type())) {
            num.setText("");
            chanpin_zl.setText("");
        } else {
            num.setText(list.size() + "");
        }
        List<String> spinnerList = new ArrayList<String>();
        if (chaXunDetailBean1.getBh_status().equals("1")) {
            if (chaXunDetailBean1.getExpress_two() != null) {
                mail_list = new String[2];
            } else {
                if (chaXunDetailBean1.getPartner_type().equals("1")) {
                    if (chaXunDetailBean1.getExpress_one() != null) {
                        mail_list = new String[1];
                    }
                } else {
                    mail_list = new String[1];
                }
            }
            if (chaXunDetailBean1.getPartner_type().equals("1")) {
                if (chaXunDetailBean1.getExpress_one() != null) {
                    mail_list[0] = chaXunDetailBean1.getExpress_one().getKuaidinum();
                    spinnerList.add(chaXunDetailBean1.getExpress_one().getKuaidinum());
                }
            } else {
                mail_list[0] = chaXunDetailBean1.getExpress_sn();
                spinnerList.add(chaXunDetailBean1.getExpress_sn());
            }
            if (chaXunDetailBean1.getExpress_two() != null) {
                mail_list[1] = chaXunDetailBean1.getExpress_two().getKuaidinum();
                spinnerList.add(chaXunDetailBean1.getExpress_two().getKuaidinum());
            }
        } else {
            if (chaXunDetailBean1.getPartner_type().equals("1")) {
                if (chaXunDetailBean1.getExpress_one() != null) {
                    mail_list = new String[1];
                    mail_list[0] = chaXunDetailBean1.getExpress_one().getKuaidinum();
                    spinnerList.add(chaXunDetailBean1.getExpress_one().getKuaidinum());
                }
            } else {
                mail_list = new String[1];
                mail_list[0] = chaXunDetailBean1.getExpress_sn();
                spinnerList.add(chaXunDetailBean1.getExpress_sn());
            }
        }
        spinner1.attachDataSource(spinnerList);
        boolean finalIsBuFa = isBuFa;
        spinner1.setOnSpinnerItemSelectedListener(new OnSpinnerItemSelectedListener() {
            @Override
            public void onItemSelected(NiceSpinner parent, View view, int position, long id) {
                if (position == 0) {
                    list.clear();
                    for (int i = 0; i < chaXunDetailBean1.getItems_one().size(); i++) {
                        ChaXunDetailBean bean = new ChaXunDetailBean();
                        bean.setSn(chaXunDetailBean1.getItems_one().get(i).getSerial_code());
                        bean.setName(chaXunDetailBean1.getItems_one().get(i).getGoods_name());
                        bean.setModel(chaXunDetailBean1.getItems_one().get(i).getGoods_model());
                        bean.setTime(chaXunDetailBean1.getItems_one().get(i).getCk_time());
                        list.add(bean);
                    }

                    if (finalIsBuFa) {
                        if (chaXunDetailBean1.getItems_two() != null)
                            for (int i = 0; i < chaXunDetailBean1.getItems_two().size(); i++) {
                                ChaXunDetailBean bean = new ChaXunDetailBean();
                                bean.setSn(chaXunDetailBean1.getItems_two().get(i).getSerial_code());
                                bean.setName(chaXunDetailBean1.getItems_two().get(i).getGoods_name());
                                bean.setModel(chaXunDetailBean1.getItems_two().get(i).getGoods_model());
                                bean.setTime(chaXunDetailBean1.getItems_two().get(i).getCk_time());
                                list.add(bean);
                            }
                    }
                    if (chaXunDetailBean1.getOrder_two_items_one() != null)
                        for (int i = 0; i < chaXunDetailBean1.getOrder_two_items_one().size(); i++) {
                            ChaXunDetailBean bean = new ChaXunDetailBean();
                            bean.setSn(chaXunDetailBean1.getOrder_two_items_one().get(i).getSerial_code());
                            bean.setName(chaXunDetailBean1.getOrder_two_items_one().get(i).getGoods_name());
                            bean.setModel(chaXunDetailBean1.getOrder_two_items_one().get(i).getGoods_model());
                            bean.setTime(chaXunDetailBean1.getOrder_two_items_one().get(i).getCk_time());
                            list.add(bean);
                        }
                    adapter.clear();
                    adapter.addAll(list);
                    num.setText(list.size() + "");
                    if (!TextUtils.isEmpty(chaXunDetailBean1.getExpress_one().getActual_weight())) {
                        sjzl.setText(chaXunDetailBean1.getExpress_one().getActual_weight() + "g");
                    } else {
                        if (!TextUtils.isEmpty(chaXunDetailBean1.getActual_weight()))
                            sjzl.setText(chaXunDetailBean1.getActual_weight().replace("g", "") + "g");
                    }
                    name = chaXunDetailBean1.getExpress_user_name();
                    mobile = chaXunDetailBean1.getExpress_user_tel();
                    address = chaXunDetailBean1.getExpress_address();

                    if (chaXunDetailBean1.getPartner_type().equals("1")) {
                        order_type.setText("系统生成");
                        mail_name.setText(chaXunDetailBean1.getExpress_one().getExp_type());
                        mail_code.setText(chaXunDetailBean1.getExpress_one().getKuaidinum());
                        if (chaXunDetailBean1.getExpress_one() != null) {
                            if(!TextUtils.isEmpty(chaXunDetailBean1.getExpress_one().getCube())) {
                                chicun.setText(chaXunDetailBean1.getExpress_one().getCube());
                            }else{
                                if (!TextUtils.isEmpty(chaXunDetailBean1.getCube()))
                                    chicun.setText(chaXunDetailBean1.getCube());
                            }
                        }else{
                            if (!TextUtils.isEmpty(chaXunDetailBean1.getCube()))
                                chicun.setText(chaXunDetailBean1.getCube());
                        }
                        if (!TextUtils.isEmpty(chaXunDetailBean1.getTotal_weight()))
                            chanpin_zl.setText(chaXunDetailBean1.getTotal_weight().replace("g", "") + "g");
                    } else {
                        order_type.setText("手动输入");
                        mail_name.setText(chaXunDetailBean1.getExpress_name());
                        mail_code.setText(chaXunDetailBean1.getExpress_sn());
                        chicun.setText(chaXunDetailBean1.getCube());
                        if (!TextUtils.isEmpty(chaXunDetailBean1.getTotal_weight()))
                            chanpin_zl.setText(chaXunDetailBean1.getTotal_weight().replace("g", "") + "g");
                    }
                } else {
                    list.clear();
                    for (int i = 0; i < chaXunDetailBean1.getItems_one().size(); i++) {
                        ChaXunDetailBean bean = new ChaXunDetailBean();
                        bean.setSn(chaXunDetailBean1.getItems_one().get(i).getSerial_code());
                        bean.setName(chaXunDetailBean1.getItems_one().get(i).getGoods_name());
                        bean.setModel(chaXunDetailBean1.getItems_one().get(i).getGoods_model());
                        bean.setTime(chaXunDetailBean1.getItems_one().get(i).getCk_time());
                        list.add(bean);
                    }
                    if (finalIsBuFa) {
                        if (chaXunDetailBean1.getItems_two() != null)
                            for (int i = 0; i < chaXunDetailBean1.getItems_two().size(); i++) {
                                ChaXunDetailBean bean = new ChaXunDetailBean();
                                bean.setSn(chaXunDetailBean1.getItems_two().get(i).getSerial_code());
                                bean.setName(chaXunDetailBean1.getItems_two().get(i).getGoods_name());
                                bean.setModel(chaXunDetailBean1.getItems_two().get(i).getGoods_model());
                                bean.setTime(chaXunDetailBean1.getItems_two().get(i).getCk_time());
                                list.add(bean);
                            }
                    }
                    adapter.clear();
                    adapter.addAll(list);

                    num.setText(list.size() + "");
                    if (!TextUtils.isEmpty(chaXunDetailBean1.getExpress_two().getTotal_weight()))
                        chanpin_zl.setText(chaXunDetailBean1.getExpress_two().getTotal_weight().replace("g", "") + "g");
                    chicun.setText(chaXunDetailBean1.getExpress_two().getCube());
                    if (!TextUtils.isEmpty(chaXunDetailBean1.getExpress_two().getActual_weight())) {
                        sjzl.setText(chaXunDetailBean1.getExpress_two().getActual_weight().replace("g", "") + "g");
                    }
                    name = chaXunDetailBean1.getExpress_user_name();
                    mobile = chaXunDetailBean1.getExpress_user_tel();
                    address = chaXunDetailBean1.getExpress_address();

                    order_type.setText("系统生成");
                    mail_name.setText(chaXunDetailBean1.getExpress_two().getExp_type());
                    mail_code.setText(chaXunDetailBean1.getExpress_two().getKuaidinum());
                }
            }
        });
    }

    @Override
    public void getInto42Success(BaseModel<ChaXunDetailBean2> o) {
        chaXunDetailBean2 = o.getData();
        if (chaXunDetailBean2.getList_data().size() == 0) {
            ToastUtil.getInstance()._short(getActivity(), "数据异常");
            playRing("shujuwuxiao.mp3");
            return;
        }
        playRing("shujuyouxiao.mp3");
        orderid.setText(orderCode);
        orderid.setBackgroundResource(R.drawable.et_grey);

        boolean isBf = false;
        boolean isBuFa = false;
        code_num1.setText(chaXunDetailBean2.getList_data().size() + "");
        if (chaXunDetailBean2.getList_data().get(0).getBh_status().equals("1")) {
            send_out_type.setText("补发");
            isBuFa = true;
        } else {
            if (chaXunDetailBean2.getList_data().get(0).getMerger_status().equals("0")) {
                send_out_type.setText("首发");
            } else {
                send_out_type.setText("并发");
                isBf = true;
            }
        }
        newOrderType = chaXunDetailBean2.getList_data().get(0).getNew_order_type();
        if ("2".equals(chaXunDetailBean2.getList_data().get(0).getNew_order_type())) {
            send_out_type.setText("刷单");
        }
        list.clear();
        for (int i = 0; i < chaXunDetailBean2.getList_data().get(0).getItems_one().size(); i++) {
            ChaXunDetailBean bean = new ChaXunDetailBean();
            bean.setSn(chaXunDetailBean2.getList_data().get(0).getItems_one().get(i).getSerial_code());
            bean.setName(chaXunDetailBean2.getList_data().get(0).getItems_one().get(i).getGoods_name());
            bean.setModel(chaXunDetailBean2.getList_data().get(0).getItems_one().get(i).getGoods_model());
            bean.setTime(chaXunDetailBean2.getList_data().get(0).getItems_one().get(i).getCk_time());
            list.add(bean);
        }

        if (isBf)
            if (chaXunDetailBean2.getList_data().get(0).getOrder_two_items_one() != null)
                for (int i = 0; i < chaXunDetailBean2.getList_data().get(0).getOrder_two_items_one().size(); i++) {
                    ChaXunDetailBean bean = new ChaXunDetailBean();
                    bean.setSn(chaXunDetailBean2.getList_data().get(0).getOrder_two_items_one().get(i).getSerial_code());
                    bean.setName(chaXunDetailBean2.getList_data().get(0).getOrder_two_items_one().get(i).getGoods_name());
                    bean.setModel(chaXunDetailBean2.getList_data().get(0).getOrder_two_items_one().get(i).getGoods_model());
                    bean.setTime(chaXunDetailBean2.getList_data().get(0).getOrder_two_items_one().get(i).getCk_time());
                    list.add(bean);
                }

        adapter.clear();
        adapter.addAll(list);
        if (isBf) {
            userInfo.setText(chaXunDetailBean2.getList_data().get(0).getHb_shr_info());
        } else {
            userInfo.setText(chaXunDetailBean2.getList_data().get(0).getExpress_user_name() + " " +
                    chaXunDetailBean2.getList_data().get(0).getExpress_user_tel() + "\n" +
                    chaXunDetailBean2.getList_data().get(0).getExpress_address());
        }
        if (isBf) {
            content.setText(chaXunDetailBean2.getList_data().get(0).getHb_order_details());
        } else {
            content.setText(chaXunDetailBean2.getList_data().get(0).getOrder_details());
        }

//        float weight = 0;
//        for (int i = 0; i < list.size(); i++) {
//            weight = weight + chaXunDetailBean2.getList_data().get(0).getItems_one().get(i).getWeight();
//        }
        if (isBf) {
            chanpin_zl.setText(chaXunDetailBean2.getList_data().get(0).getCount_shop_weight().replace("g", "") + "g");
        } else {
            chanpin_zl.setText(chaXunDetailBean2.getList_data().get(0).getTotal_weight().replace("g", "") + "g");
        }
        chicun.setText(chaXunDetailBean2.getList_data().get(0).getCube());
        if (!TextUtils.isEmpty(chaXunDetailBean2.getList_data().get(0).getActual_weight())) {
            sjzl.setText(chaXunDetailBean2.getList_data().get(0).getActual_weight().replace("g", "") + "g");
        }
        name = chaXunDetailBean2.getList_data().get(0).getExpress_user_name();
        mobile = chaXunDetailBean2.getList_data().get(0).getExpress_user_tel();
        address = chaXunDetailBean2.getList_data().get(0).getExpress_address();
        if ("2".equals(chaXunDetailBean2.getList_data().get(0).getNew_order_type())) {
            num.setText("");
            chanpin_zl.setText("");
        } else {
            num.setText(list.size() + "");
        }
        mail_name1.setText(chaXunDetailBean2.getList_data().get(0).getExp_type());
        mail_code1.setText(chaXunDetailBean2.getList_data().get(0).getOrder_sn());
        if (chaXunDetailBean2.getList_data().get(0).getPartner_type().equals("1")) {
            order_type1.setText("系统生成");
            dayin_img.setVisibility(View.VISIBLE);
        } else {
            order_type1.setText("手动输入");
            dayin_img.setVisibility(View.GONE);
        }

        mPresenter.Into43(chaXunDetailBean2.getList_data().get(0).getOrder_sn());
        mail_list1 = new String[chaXunDetailBean2.getList_data().size()];
        List<String> spinnerList = new ArrayList<String>();
        for (int i = 0; i < chaXunDetailBean2.getList_data().size(); i++) {
            mail_list1[i] = chaXunDetailBean2.getList_data().get(i).getOrder_sn();
            spinnerList.add(chaXunDetailBean2.getList_data().get(i).getOrder_sn());
        }
        spinner2.attachDataSource(spinnerList);
        spinner2.setOnSpinnerItemSelectedListener(new OnSpinnerItemSelectedListener() {
            @Override
            public void onItemSelected(NiceSpinner parent, View view, int position, long id) {
                boolean isBf = false;
                if (chaXunDetailBean2.getList_data().get(position).getBh_status().equals("1")) {
                    send_out_type.setText("补发");
                    code_num.setText("2");
                } else {
                    if (chaXunDetailBean2.getList_data().get(position).getMerger_status().equals("0")) {
                        send_out_type.setText("首发");
                        code_num.setText("1");
                    } else {
                        send_out_type.setText("并发");
                        code_num.setText("1");
                        isBf = true;
                    }
                }
                newOrderType = chaXunDetailBean2.getList_data().get(position).getNew_order_type();
                if ("2".equals(chaXunDetailBean2.getList_data().get(position).getNew_order_type())) {
                    send_out_type.setText("刷单");
                    code_num.setText("1");
                }
                list.clear();
                for (int i = 0; i < chaXunDetailBean2.getList_data().get(position).getItems_one().size(); i++) {
                    ChaXunDetailBean bean = new ChaXunDetailBean();
                    bean.setSn(chaXunDetailBean2.getList_data().get(position).getItems_one().get(i).getSerial_code());
                    bean.setName(chaXunDetailBean2.getList_data().get(position).getItems_one().get(i).getGoods_name());
                    bean.setModel(chaXunDetailBean2.getList_data().get(position).getItems_one().get(i).getGoods_model());
                    bean.setTime(chaXunDetailBean2.getList_data().get(position).getItems_one().get(i).getCk_time());
                    list.add(bean);
                }
                if (isBf) {
                    if (chaXunDetailBean2.getList_data().get(position).getOrder_two_items_one() != null)
                        for (int i = 0; i < chaXunDetailBean2.getList_data().get(position).getOrder_two_items_one().size(); i++) {
                            ChaXunDetailBean bean = new ChaXunDetailBean();
                            bean.setSn(chaXunDetailBean2.getList_data().get(position).getOrder_two_items_one().get(i).getSerial_code());
                            bean.setName(chaXunDetailBean2.getList_data().get(position).getOrder_two_items_one().get(i).getGoods_name());
                            bean.setModel(chaXunDetailBean2.getList_data().get(position).getOrder_two_items_one().get(i).getGoods_model());
                            bean.setTime(chaXunDetailBean2.getList_data().get(position).getOrder_two_items_one().get(i).getCk_time());
                            list.add(bean);
                        }
                }
                adapter.clear();
                adapter.addAll(list);

                if (isBf) {
                    userInfo.setText(chaXunDetailBean2.getList_data().get(position).getHb_shr_info());
                    content.setText(chaXunDetailBean2.getList_data().get(position).getHb_order_details());
                } else {
                    userInfo.setText(chaXunDetailBean2.getList_data().get(position).getExpress_user_name() + " " +
                            chaXunDetailBean2.getList_data().get(position).getExpress_user_tel() + "\n" +
                            chaXunDetailBean2.getList_data().get(position).getExpress_address());
                    content.setText(chaXunDetailBean2.getList_data().get(position).getOrder_details());
                }


//                float weight = 0;
//                for (int i = 0; i < list.size(); i++) {
//                    weight = weight + chaXunDetailBean2.getList_data().get(position).getItems_one().get(i).getWeight();
//                }
                if (isBf) {
                    chanpin_zl.setText(chaXunDetailBean2.getList_data().get(position).getCount_shop_weight().replace("g", "") + "g");
                } else {
                    if (!TextUtils.isEmpty(chaXunDetailBean2.getList_data().get(position).getTotal_weight()))
                        chanpin_zl.setText(chaXunDetailBean2.getList_data().get(position).getTotal_weight().replace("g", "") + "g");
                }
                chicun.setText(chaXunDetailBean2.getList_data().get(position).getCube());
                if (!TextUtils.isEmpty(chaXunDetailBean2.getList_data().get(position).getActual_weight())) {
                    sjzl.setText(chaXunDetailBean2.getList_data().get(position).getActual_weight().replace("g", "") + "g");
                }
                name = chaXunDetailBean2.getList_data().get(position).getExpress_user_name();
                mobile = chaXunDetailBean2.getList_data().get(position).getExpress_user_tel();
                address = chaXunDetailBean2.getList_data().get(position).getExpress_address();

                if ("2".equals(chaXunDetailBean2.getList_data().get(position).getNew_order_type())) {
                    num.setText("");
                    chanpin_zl.setText("");
                } else {
                    num.setText(list.size() + "");
                }

                mail_name1.setText(chaXunDetailBean2.getList_data().get(position).getExp_type());
                mail_code1.setText(chaXunDetailBean2.getList_data().get(position).getOrder_sn());
                if (chaXunDetailBean2.getList_data().get(position).getPartner_type().equals("1")) {
                    order_type1.setText("系统生成");
                    dayin_img.setVisibility(View.VISIBLE);
                } else {
                    order_type1.setText("手动输入");
                    dayin_img.setVisibility(View.GONE);
                }
            }
        });
    }

    @Override
    public void getInto43Success(BaseModel<List<SendRecordBean>> o) {
        recordBeans = o.getData();
    }

    @Override
    public void onDataError() {
        playRing("shujuwuxiao.mp3");
    }

    @Override
    public void onUpFail(String mag) {
        MyDialogUtil.showDialog(getActivity(), mag);
        playRing("wuxiao.mp3");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick({R.id.dayin_img, R.id.logistics, R.id.logistics1, R.id.search_type, R.id.qingkong1, R.id.fhjl, R.id.fhjl1, R.id.mail_code, R.id.mail_code1})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.dayin_img:
                if (!ZPLPrinterHelper.IsOpened()) {
                    ToastUtil.getInstance()._short(mContext, "打印机连接失败");
                }
                if (!dyjStatus) {
                    return;
                }

                String pic = "";
                if (((int) search_type.getTag()) == 0) {
                    if (page1 == 0) {
                        pic = chaXunDetailBean1.getExpress_one().getImg_base64();
                    } else {
                        pic = chaXunDetailBean1.getExpress_two().getImg_base64();
                    }
                } else {
                    pic = chaXunDetailBean2.getList_data().get(page2).getImg_base64();
                }
                if (TextUtils.isEmpty(pic)) {
                    ToastUtils.showShort("未获取到图片，请先去生成");
                    return;
                }
//                ImgDialog imgDialog = new ImgDialog(getActivity(), pic);
//                imgDialog.show();
                String finalPic = pic;
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            Bitmap bitmap = GlideImageLoader.getBitmap(BaseUrl.url1 + finalPic);
                            if (TextUtils.isEmpty(MainActivity.userInfoBean.getPrint_paper_width())) {
                                ToastUtil.getInstance()._short(mContext, "纸张宽度不能为空");
                                return;
                            }
                            if (TextUtils.isEmpty(MainActivity.userInfoBean.getPrint_deviation_x())) {
                                ToastUtil.getInstance()._short(mContext, "水平偏移不能为空");
                                return;
                            }
                            if (TextUtils.isEmpty(MainActivity.userInfoBean.getPrint_deviation_y())) {
                                ToastUtil.getInstance()._short(mContext, "垂直偏移不能为空");
                                return;
                            }
                            MainActivity.mZPL.start();
                            MainActivity.mZPL.printData("^LL" + bitmap.getHeight() + "\r\n");
                            MainActivity.mZPL.PW(MainActivity.userInfoBean.getPrint_paper_width());
                            MainActivity.mZPL.printBitmap(MainActivity.userInfoBean.getPrint_deviation_x(),
                                    MainActivity.userInfoBean.getPrint_deviation_y(), bitmap);

                            int i = MainActivity.mZPL.end();
                            System.out.println("111111111111111:" + i);
                            Looper.prepare();
                            if (i == 0) {
                                DayinDialog1 dayinDialog1 = new DayinDialog1(getActivity(), i + "");
                                dayinDialog1.show();
                                playRing("dayinwancheng.mp3");
                            } else {
                                DayinDialog2 dayinDialog2 = new DayinDialog2(getActivity(), i + "");
                                dayinDialog2.show();
                                playRing("shibai.mp3");
                            }
                            Looper.loop();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }).start();
                break;
            case R.id.search_type:
                XPopup.get(getActivity()).asCenterList("请选择查询类型", new String[]{"订单编号", "快递单号"},
                        new OnSelectListener() {
                            @Override
                            public void onSelect(int position, String text) {
                                search_type.setText(text);
                                search_type.setTag(position);
                                tv_search_type.setText(text + ":");

                                chaXunDetailBean1 = null;
                                list.clear();
                                adapter.clear();
                                adapter.notifyDataSetChanged();
                                send_out_type.setText("");
                                code_num.setText("");
                                code_num1.setText("");
                                userInfo.setText("");
                                content.setText("");
                                num.setText("0");
                                chanpin_zl.setText("");
                                chicun.setText("");
                                sjzl.setText("");
                                orderid.setText("");
                                name = "";
                                mobile = "";
                                address = "";

                                order_type.setText("");
                                mail_name.setText("");
                                mail_code.setText("");
                                mail_list = null;
                                order_type1.setText("");
                                mail_name1.setText("");
                                mail_code1.setText("");
                                mail_list1 = null;
//                                if (position == 0) {
//                                    onBarcodeEvent("XSDD20220215-00004");
//                                } else {
//                                    onBarcodeEvent("773148257446661");
//                                }
                                if (position == 0) {
                                    mail_ll1.setVisibility(View.GONE);
                                    mail_ll2.setVisibility(View.VISIBLE);
                                } else {
                                    mail_ll1.setVisibility(View.VISIBLE);
                                    mail_ll2.setVisibility(View.GONE);
                                }
                            }
                        })
                        .show();
                break;
            case R.id.logistics:
                if ((int) search_type.getTag() == 0) {
                    if (chaXunDetailBean1 == null) {
                        return;
                    }
                    if (chaXunDetailBean1.getPartner_type().equals("1")) {
                        if (page1 == 0) {
                            if (chaXunDetailBean1.getExpress_one() != null)
                                getActivity().startActivity(new Intent(getActivity(), LogisticsActivity.class)
                                        .putExtra("express_sn", chaXunDetailBean1.getExpress_one().getKuaidinum())
                                        .putExtra("type", chaXunDetailBean1.getBh_status())
                                        .putExtra("order_sn", chaXunDetailBean1.getOrder_sn())
                                        .putExtra("express_code", chaXunDetailBean1.getExpress_one().getKuaidicom()));
                        } else {
                            if (chaXunDetailBean1.getExpress_two() != null)
                                getActivity().startActivity(new Intent(getActivity(), LogisticsActivity.class)
                                        .putExtra("express_sn", chaXunDetailBean1.getExpress_two().getKuaidinum())
                                        .putExtra("type", chaXunDetailBean1.getBh_status())
                                        .putExtra("order_sn", chaXunDetailBean1.getOrder_sn())
                                        .putExtra("express_code", chaXunDetailBean1.getExpress_two().getKuaidicom()));
                        }
                    } else {
                        getActivity().startActivity(new Intent(getActivity(), LogisticsActivity.class)
                                .putExtra("express_sn", chaXunDetailBean1.getExpress_sn())
                                .putExtra("type", chaXunDetailBean1.getBh_status())
                                .putExtra("order_sn", chaXunDetailBean1.getOrder_sn())
                                .putExtra("express_code", chaXunDetailBean1.getKuaidicom()));
                    }
                }
                break;
            case R.id.logistics1:
                if ((int) search_type.getTag() == 1) {
                    if (chaXunDetailBean2 == null) {
                        return;
                    }
                    getActivity().startActivity(new Intent(getActivity(), LogisticsActivity.class)
                            .putExtra("express_sn", chaXunDetailBean2.getList_data().get(page2).getExpress_sn())
                            .putExtra("type", chaXunDetailBean2.getList_data().get(page2).getBh_status())
                            .putExtra("order_sn", chaXunDetailBean2.getList_data().get(page2).getOrder_sn())
                            .putExtra("express_code", chaXunDetailBean2.getList_data().get(page2).getKuaidicom()));
                }
                break;
            case R.id.fhjl:
                if (recordBeans != null && recordBeans.size() > 0) {
                    SendRecordDialog sendRecordDialog1 = new SendRecordDialog(getActivity(), recordBeans);
                    sendRecordDialog1.show();
                }
                break;
            case R.id.fhjl1:
                if (recordBeans != null && recordBeans.size() > 0) {
                    SendRecordDialog sendRecordDialog2 = new SendRecordDialog(getActivity(), recordBeans);
                    sendRecordDialog2.show();
                }
                break;
            case R.id.qingkong1:
                orderid.setText("");
                chaXunDetailBean1 = null;
                list.clear();
                adapter.clear();
                adapter.notifyDataSetChanged();
                send_out_type.setText("");
                code_num.setText("");
                code_num1.setText("");
                userInfo.setText("");
                content.setText("");
                num.setText("0");
                chanpin_zl.setText("");
                chicun.setText("");
                sjzl.setText("");
                name = "";
                mobile = "";
                address = "";

                order_type.setText("");
                mail_name.setText("");
                mail_code.setText("");
                mail_list = null;
                order_type1.setText("");
                mail_name1.setText("");
                mail_code1.setText("");
                mail_list1 = null;

                orderid.setBackgroundResource(R.drawable.et_yellow);
                dayin_img.setVisibility(View.GONE);
                playRing("qingkong.mp3");
                break;
            case R.id.mail_code:
                if (mail_list != null && mail_list.length > 0) {
                    XPopup.get(getActivity()).asCenterList("请选择类型", mail_list, new OnSelectListener() {
                        @Override
                        public void onSelect(int position, String text) {
                            page1 = position;
                            if (position == 0) {
                                list.clear();
                                for (int i = 0; i < chaXunDetailBean1.getItems_one().size(); i++) {
                                    ChaXunDetailBean bean = new ChaXunDetailBean();
                                    bean.setSn(chaXunDetailBean1.getItems_one().get(i).getSerial_code());
                                    bean.setName(chaXunDetailBean1.getItems_one().get(i).getGoods_name());
                                    bean.setModel(chaXunDetailBean1.getItems_one().get(i).getGoods_model());
                                    bean.setTime(chaXunDetailBean1.getItems_one().get(i).getCk_time());
                                    list.add(bean);
                                }
                                adapter.clear();
                                adapter.addAll(list);
                                num.setText(list.size() + "");

                                if (chaXunDetailBean1.getExpress_one() != null && !TextUtils.isEmpty(chaXunDetailBean1.getExpress_one().getActual_weight())) {
                                    sjzl.setText(chaXunDetailBean1.getExpress_one().getActual_weight().replace("g", "") + "g");
                                } else {
                                    if (!TextUtils.isEmpty(chaXunDetailBean1.getActual_weight()))
                                        sjzl.setText(chaXunDetailBean1.getActual_weight().replace("g", "") + "g");
                                }
                                name = chaXunDetailBean1.getExpress_user_name();
                                mobile = chaXunDetailBean1.getExpress_user_tel();
                                address = chaXunDetailBean1.getExpress_address();

                                if (chaXunDetailBean1.getPartner_type().equals("1")) {
                                    order_type.setText("系统生成");
                                    mail_name.setText(chaXunDetailBean1.getExpress_one().getExp_type());
                                    mail_code.setText(chaXunDetailBean1.getExpress_one().getKuaidinum());
                                    if (chaXunDetailBean1.getBh_status().equals("1")) {
                                        chicun.setText(chaXunDetailBean1.getExpress_one().getCube());
                                        if (!TextUtils.isEmpty(chaXunDetailBean1.getExpress_one().getTotal_weight()))
                                            chanpin_zl.setText(chaXunDetailBean1.getExpress_one().getTotal_weight().replace("g", "") + "g");
                                    } else {
                                        chicun.setText(chaXunDetailBean1.getCube());
                                        if (!TextUtils.isEmpty(chaXunDetailBean1.getTotal_weight()))
                                            chanpin_zl.setText(chaXunDetailBean1.getTotal_weight().replace("g", "") + "g");
                                    }
                                } else {
                                    order_type.setText("手动输入");
                                    mail_name.setText(chaXunDetailBean1.getExpress_name());
                                    mail_code.setText(chaXunDetailBean1.getExpress_sn());
                                    chicun.setText(chaXunDetailBean1.getCube());
                                    if (!TextUtils.isEmpty(chaXunDetailBean1.getTotal_weight()))
                                        chanpin_zl.setText(chaXunDetailBean1.getTotal_weight().replace("g", "") + "g");
                                }
                            } else {
                                list.clear();
                                for (int i = 0; i < chaXunDetailBean1.getItems_two().size(); i++) {
                                    ChaXunDetailBean bean = new ChaXunDetailBean();
                                    bean.setSn(chaXunDetailBean1.getItems_two().get(i).getSerial_code());
                                    bean.setName(chaXunDetailBean1.getItems_two().get(i).getGoods_name());
                                    bean.setModel(chaXunDetailBean1.getItems_two().get(i).getGoods_model());
                                    bean.setTime(chaXunDetailBean1.getItems_two().get(i).getCk_time());
                                    list.add(bean);
                                }

                                if (chaXunDetailBean1.getOrder_two_items_two() != null)
                                    for (int i = 0; i < chaXunDetailBean1.getOrder_two_items_two().size(); i++) {
                                        ChaXunDetailBean bean = new ChaXunDetailBean();
                                        bean.setSn(chaXunDetailBean1.getOrder_two_items_two().get(i).getSerial_code());
                                        bean.setName(chaXunDetailBean1.getOrder_two_items_two().get(i).getGoods_name());
                                        bean.setModel(chaXunDetailBean1.getOrder_two_items_two().get(i).getGoods_model());
                                        bean.setTime(chaXunDetailBean1.getOrder_two_items_two().get(i).getCk_time());
                                        list.add(bean);
                                    }


                                adapter.clear();
                                adapter.addAll(list);
                                num.setText(list.size() + "");
//                                float weight = 0;
//                                for (int i = 0; i < list.size(); i++) {
//                                    weight = weight + chaXunDetailBean1.getItems_two().get(i).getWeight();
//                                }
                                if (!TextUtils.isEmpty(chaXunDetailBean1.getExpress_two().getTotal_weight()))
                                    chanpin_zl.setText(chaXunDetailBean1.getExpress_two().getTotal_weight().replace("g", "") + "g");
                                chicun.setText(chaXunDetailBean1.getExpress_two().getCube());
                                if (chaXunDetailBean1.getExpress_two() != null && !TextUtils.isEmpty(chaXunDetailBean1.getExpress_two().getActual_weight())) {
                                    sjzl.setText(chaXunDetailBean1.getExpress_two().getActual_weight().replace("g", "") + "g");
                                } else {
                                    sjzl.setText("");
                                }
                                name = chaXunDetailBean1.getExpress_user_name();
                                mobile = chaXunDetailBean1.getExpress_user_tel();
                                address = chaXunDetailBean1.getExpress_address();

                                order_type.setText("系统生成");
                                mail_name.setText(chaXunDetailBean1.getExpress_two().getExp_type());
                                mail_code.setText(chaXunDetailBean1.getExpress_two().getKuaidinum());

                            }
                        }
                    }).show();
                }
                break;
            case R.id.mail_code1:
                if (mail_list1 != null && mail_list1.length > 0) {
                    XPopup.get(getActivity()).asCenterList("请选择类型", mail_list1,
                            new OnSelectListener() {
                                @Override
                                public void onSelect(int position, String text) {
                                    page2 = position;

                                    mPresenter.Into43(chaXunDetailBean2.getList_data().get(position).getOrder_sn());
                                    list.clear();
                                    for (int i = 0; i < chaXunDetailBean2.getList_data().get(position).getItems_one().size(); i++) {
                                        ChaXunDetailBean bean = new ChaXunDetailBean();
                                        bean.setSn(chaXunDetailBean2.getList_data().get(position).getItems_one().get(i).getSerial_code());
                                        bean.setName(chaXunDetailBean2.getList_data().get(position).getItems_one().get(i).getGoods_name());
                                        bean.setModel(chaXunDetailBean2.getList_data().get(position).getItems_one().get(i).getGoods_model());
                                        bean.setTime(chaXunDetailBean2.getList_data().get(position).getItems_one().get(i).getCk_time());
                                        list.add(bean);
                                    }
                                    adapter.clear();
                                    adapter.addAll(list);
                                    if (chaXunDetailBean2.getList_data().get(position).getBh_status().equals("1")) {
                                        send_out_type.setText("补发");
                                        code_num.setText("2");
                                    } else {
                                        if (chaXunDetailBean2.getList_data().get(position).getMerger_status().equals("0")) {
                                            send_out_type.setText("首发");
                                            code_num.setText("1");
                                        } else {
                                            send_out_type.setText("并发");
                                            code_num.setText("1");
                                        }
                                    }

                                    newOrderType = chaXunDetailBean2.getList_data().get(position).getNew_order_type();
                                    if ("2".equals(chaXunDetailBean2.getList_data().get(position).getNew_order_type())) {
                                        send_out_type.setText("刷单");
                                        code_num.setText("1");
                                    }
                                    list.clear();
                                    for (int i = 0; i < chaXunDetailBean2.getList_data().get(position).getItems_one().size(); i++) {
                                        ChaXunDetailBean bean = new ChaXunDetailBean();
                                        bean.setSn(chaXunDetailBean2.getList_data().get(position).getItems_one().get(i).getSerial_code());
                                        bean.setName(chaXunDetailBean2.getList_data().get(position).getItems_one().get(i).getGoods_name());
                                        bean.setModel(chaXunDetailBean2.getList_data().get(position).getItems_one().get(i).getGoods_model());
                                        bean.setTime(chaXunDetailBean2.getList_data().get(position).getItems_one().get(i).getCk_time());
                                        list.add(bean);
                                    }
                                    adapter.clear();
                                    adapter.addAll(list);
                                    userInfo.setText(chaXunDetailBean2.getList_data().get(position).getExpress_user_name() + " " +
                                            chaXunDetailBean2.getList_data().get(position).getExpress_user_tel() + "\n" +
                                            chaXunDetailBean2.getList_data().get(position).getExpress_address());
                                    content.setText(chaXunDetailBean2.getList_data().get(position).getOrder_details());

//                                    float weight = 0;
//                                    for (int i = 0; i < list.size(); i++) {
//                                        weight = weight + chaXunDetailBean2.getList_data().get(position).getItems_one().get(i).getWeight();
//                                    }
                                    if (!TextUtils.isEmpty(chaXunDetailBean2.getList_data().get(position).getTotal_weight()))
                                        chanpin_zl.setText(chaXunDetailBean2.getList_data().get(position).getTotal_weight().replace("g", "") + "g");
                                    chicun.setText(chaXunDetailBean2.getList_data().get(position).getCube());
                                    System.out.println("000000:" + chaXunDetailBean2.getList_data().get(position).getActual_weight());
                                    if (!TextUtils.isEmpty(chaXunDetailBean2.getList_data().get(position).getActual_weight())) {
                                        sjzl.setText(chaXunDetailBean2.getList_data().get(position).getActual_weight().replace("g", "") + "g");
                                    }
                                    name = chaXunDetailBean2.getList_data().get(position).getExpress_user_name();
                                    mobile = chaXunDetailBean2.getList_data().get(position).getExpress_user_tel();
                                    address = chaXunDetailBean2.getList_data().get(position).getExpress_address();
                                    if ("2".equals(chaXunDetailBean2.getList_data().get(position).getNew_order_type())) {
                                        num.setText("");
                                        chanpin_zl.setText("");
                                    } else {
                                        num.setText(list.size() + "");
                                    }
                                    mail_name1.setText(chaXunDetailBean2.getList_data().get(position).getExp_type());
                                    mail_code1.setText(chaXunDetailBean2.getList_data().get(position).getOrder_sn());
                                    if (chaXunDetailBean2.getList_data().get(position).getPartner_type().equals("1")) {
                                        order_type1.setText("系统生成");
                                        dayin_img.setVisibility(View.VISIBLE);
                                    } else {
                                        order_type1.setText("手动输入");
                                        dayin_img.setVisibility(View.GONE);
                                    }
                                }
                            })
                            .show();
                }
                break;
        }

    }

    public void onBarcodeEvent(String code) {
        System.out.println("扫描结果1：" + code);
        if (TextUtils.isEmpty(orderid.getText().toString().trim())) {
            orderCode = code;
            if ((int) search_type.getTag() == 0) {
                mPresenter.Into41(code);
            } else {
                mPresenter.Into42(code);
            }
        } else {
        }
    }

    private AssetManager assetManager;
    private MediaPlayer player = new MediaPlayer();

    private void playRing(String fileName) {
        try {
            assetManager = getActivity().getAssets();
            AssetFileDescriptor fileDescriptor = assetManager.openFd(fileName);
            player.reset();
            player.setDataSource(fileDescriptor.getFileDescriptor(), fileDescriptor.getStartOffset(),
                    fileDescriptor.getLength());
            player.prepare();
            player.start();
            player.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() {
                @Override
                public void onSeekComplete(MediaPlayer mp) {
                    player.stop();
                }
            });

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void playUrl(String fileName, final int i) {
        if (TextUtils.isEmpty(fileName)) {
            if (i == 1) {
                playRing("luruchenggong.mp3");
                return;
            } else {
                playRing("wuxiao.mp3");
                return;
            }
        }
        try {
            player.reset();
            if (!fileName.contains("http")) {
                player.setDataSource(BaseUrl.mp3Url + fileName);
            } else {
                player.setDataSource(fileName);
            }
            player.prepare();
            player.start();
            player.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() {
                @Override
                public void onSeekComplete(MediaPlayer mp) {
                    if (i == 1) {
                        playRing("luruchenggong.mp3");
                    } else {
                        playRing("wuxiao.mp3");
                    }
                }
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onPause() {
        handler1.removeMessages(1);
        if (player.isPlaying()) {
            player.stop();
        }
        super.onPause();
    }

    @Override
    public void onResume() {
        super.onResume();
        handler1.sendEmptyMessage(1);
    }

    @Override
    public void onDestroy() {
        player.release();
        super.onDestroy();
    }

    public static Bitmap setImage(String imageStr) {
        byte[] decode = Base64.decode(imageStr, Base64.DEFAULT);
        return BitmapFactory.decodeByteArray(decode, 0, decode.length);
    }

    public void getDayinStatus() {
        try {
            MainActivity.mZPL.WriteData("~HQES\r\n".getBytes());
            String str = byteToString(MainActivity.mZPL.ReadData(2)).replace("PRINTER STATUS ERROR:", "");
            if (str.length() > 0 && str.substring(0, 1).equals("0")) {
                dyjStatus = true;
                dayin_img.setImageResource(R.mipmap.dayin_true);
                if ((MyApplication.isDyPlay == 0 || MyApplication.isDyPlay == 2) && !MyApplication.dy_scaleIsConnect) {
                    MyApplication.isDyPlay = 1;
                    MyApplication.dy_scaleIsConnect = true;
                    playRing("lianjiesuccess.mp3");
                }
            } else {
                dyjStatus = false;
                dayin_img.setImageResource(R.mipmap.dayin_false);
                if ((MyApplication.isDyPlay == 1) && MyApplication.dy_scaleIsConnect) {
                    MyApplication.isDyPlay = 2;
                    MyApplication.dy_scaleIsConnect = false;
                    playRing("lianjieerror.mp3");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static String byteToString(byte[] bytes) {
        if (null == bytes || bytes.length == 0) {
            return "";
        }
        String strContent = "";
        try {
            strContent = new String(bytes, "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return strContent;
    }
}
